Skip to content

feat: delete_session() cascades subagent transcript dir#805

Merged
qing-ant merged 1 commit intomainfrom
qing/delete-session-subagent-cascade
Apr 14, 2026
Merged

feat: delete_session() cascades subagent transcript dir#805
qing-ant merged 1 commit intomainfrom
qing/delete-session-subagent-cascade

Conversation

@qing-ant
Copy link
Copy Markdown
Contributor

@qing-ant qing-ant commented Apr 9, 2026

Aligns delete_session() with the TS SDK filesystem behavior. after removing {session_id}.jsonl, also remove the sibling {session_id}/ subdirectory that holds subagent transcripts.

The subagent dir is removed best-effort (shutil.rmtree(..., ignore_errors=True)) since most sessions never spawn subagents. The existing FileNotFoundError when the .jsonl itself is missing is unchanged.

Adds a regression test under TestDeleteSession.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — simple best-effort cascade deletion with proper guard and a regression test.

Extended reasoning...

Overview

Adds a single call at the end of to clean up the sibling subagent transcript directory, aligning Python SDK behavior with the TS SDK. Also updates the docstring and adds one regression test.

Security risks

None. The path is constructed as where both components come from the already-validated session file path — no injection surface. prevents any information leakage via exceptions.

Level of scrutiny

Low. This is a two-line production change (plus docstring + import) that is purely additive and best-effort. The failure mode when the directory is absent is a silent no-op, which is the correct behavior described in the PR.

Other factors

No bugs found. No prior reviews. The new test covers the case where the subagent dir exists and verifies both the and the directory are removed.

IgorTavcar added a commit to IgorTavcar/claude-agent-sdk-python that referenced this pull request Apr 10, 2026
- anthropics#806: setting_sources=[] truthiness fix
- anthropics#803: betas=[]/plugins=[] truthiness fix
- anthropics#786: ThinkingBlock missing signature crash fix
- anthropics#790: suppress ProcessError when result already received
- anthropics#658: capture real stderr in ProcessError
- anthropics#791: suppress stale task notifications between turns
- anthropics#763: guard malformed CLAUDE_CODE_STREAM_CLOSE_TIMEOUT env var
- anthropics#805: delete_session() cascades subagent transcript dir
- anthropics#804: top-level skills option on ClaudeAgentOptions
- anthropics#691: PostCompact hook event type support

479 tests passing, mypy clean, ruff clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@qing-ant qing-ant enabled auto-merge (squash) April 14, 2026 05:38
Copy link
Copy Markdown
Collaborator

@bogini bogini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stamped 🦾

@qing-ant qing-ant merged commit 2038a15 into main Apr 14, 2026
10 checks passed
@qing-ant qing-ant deleted the qing/delete-session-subagent-cascade branch April 14, 2026 05:44
Flohs added a commit to Flohs/claude-agent-sdk-go that referenced this pull request Apr 15, 2026
Python SDK PR anthropics/claude-agent-sdk-python#805 aligned Python with
the TypeScript SDK by cascading the delete to the sibling `{session_id}/`
directory (which holds subagent transcripts).

Mirror that here:
- `DeleteSession` still hard-deletes the primary `.jsonl` (error on failure).
- Additionally removes the sibling dir with `os.RemoveAll`, swallowing the
  error (equivalent to Python's `shutil.rmtree(..., ignore_errors=True)`).
- Preserves the existing "session not found" behavior when the `.jsonl`
  is missing.
Flohs added a commit to Flohs/claude-agent-sdk-go that referenced this pull request Apr 15, 2026
Python SDK PR anthropics/claude-agent-sdk-python#805 aligned Python with
the TypeScript SDK by cascading the delete to the sibling `{session_id}/`
directory (which holds subagent transcripts).

Mirror that here:
- `DeleteSession` still hard-deletes the primary `.jsonl` (error on failure).
- Additionally removes the sibling dir with `os.RemoveAll`, swallowing the
  error (equivalent to Python's `shutil.rmtree(..., ignore_errors=True)`).
- Preserves the existing "session not found" behavior when the `.jsonl`
  is missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants